package com.example.administrator.hqq.fragment.module;


import android.annotation.SuppressLint;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ScrollView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.example.administrator.hqq.R;
import com.example.administrator.hqq.View.MyGridView;
import com.example.administrator.hqq.adapter.module.AddModuleGridView;
import com.example.administrator.hqq.bean.AddCheckedModuleBean;
import com.example.administrator.hqq.bean.AllModuleTopicBean;
import com.example.administrator.hqq.config.LoongsConfig;
import com.example.administrator.hqq.config.UrlFactory;
import com.google.gson.Gson;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;
import okhttp3.Call;

/**
 * A simple {@link Fragment} subclass.
 */
@SuppressLint("ValidFragment")
public class AddModuleClassifyFragment extends Fragment {

    private final String TAG = this.getClass().getSimpleName();
    Unbinder unbinder;
    @BindView(R.id.grid)
    MyGridView grid;
    @BindView(R.id.scrollView)
    ScrollView scrollView;
    private View inflate;
    private String id;
    private AddModuleGridView hobbiesAdapter;
    private List<AllModuleTopicBean.DataBean.TopicBean> data;
    private int position=-1;
    private SelectModule selectModule;
    @SuppressLint("ValidFragment")
    public AddModuleClassifyFragment(List<AllModuleTopicBean.DataBean.TopicBean> data,int position) {
        // Required empty public constructor
        this.data=data;
        this.position=position;
    }

    public void setSelectModule(SelectModule selectModule) {
        this.selectModule = selectModule;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        inflate = inflater.inflate(R.layout.fragment_add_module_classify, container, false);
        unbinder = ButterKnife.bind(this, inflate);
        initview();
        initdata();
        return inflate;
    }

    @Override
    public void onStart() {
        super.onStart();
    }

    private void initdata() {

    }

    private void initview() {
        hobbiesAdapter = new AddModuleGridView(getActivity(), data);
        grid.setSelector(new ColorDrawable(Color.TRANSPARENT));
        grid.setAdapter(hobbiesAdapter);
        grid.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @SuppressLint("ResourceAsColor")
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                data.get(i).setSelect(!data.get(i).isSelect());
                hobbiesAdapter.notifyDataSetChanged();
                if (selectModule!=null){
                    selectModule.selectModule(position,i);
                }
            }
        });
       ;
        grid.setFocusable(false);
    }
    public void notifyDataSetChanged(){
        hobbiesAdapter.notifyDataSetChanged();
    }
    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }
    public interface SelectModule{
        void selectModule(int position,int childPosition);
    }
}
